{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import jieba\n",
    "seg_list = jieba.cut(\"研究生在研究生命的起源\", cut_all = False)\n",
    "print(\"精确模式: \", \"/\".join(seg_list))\n",
    "seg_list = jieba.cut(\"研究生在研究生命的起源\", cut_all = True)\n",
    "print(\"全模式: \", \"/\".join(seg_list))\n",
    "seg_list = jieba.cut_for_search(\"研究生在研究生命的起源\")\n",
    "print(\"搜索引擎模式: \", \"/\".join(seg_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import jieba\n",
    "def TF_word(words, topk):\n",
    "    data = {}\n",
    "    for k in words:\n",
    "        data[k] += 1\n",
    "        else:\n",
    "            data[k] = 1\n",
    "            data = sorted(data.items(), key = lambda x:x[1], reverse = true)\n",
    "            return data[:topk]\n",
    "        file_content = open('data/dongaohui.txt', encoding = 'utf-8').read()\n",
    "        split_words = jieba.lcut(file_content)\n",
    "        print(\"未删除停用词的前{0}个高频词： {1}\".format(10,TF_word(split_words, 10)))\n",
    "        stop_words = [line.strip() for line in open('data/stops_list.txt', 'r', encoding = 'utf-8').readlines()]\n",
    "        stop_words.append('\\n')\n",
    "        split_words2 = [x for x in split_words if x not in stop_words]\n",
    "        print(\"删除停用词的前{0}个高频词: {1}\".format(10,TF_word(split_words2, 10)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import jieba.posseg as psg\n",
    "sent = \"研究生在研究生命的起源!\"\n",
    "seg_list = psg.cut(sent)\n",
    "print(' '.join(['{0}/(1)'.format(w, t) for w, t in seg_list]))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
